import { getUserInfoApi } from "../../api/user"
import { setToken } from "../../utils/storage"

export default {
  namespaced: true, // 开启命名空间，让模块独立
  state: () => ({
    MyuserInfo: {},
    articleNum: 0,
    zanNum: 0,
    collectNum: 0,
    hasLogin:false
  }),
  getters: {

  },
  mutations: {
    getInfo(state, { userInfo, articleNum, zanNum, collectNum }) {
      state.MyuserInfo = userInfo
      state.articleNum = articleNum
      state.zanNum = zanNum
      state.collectNum = collectNum
      setToken('username',userInfo.username)
    },
    editHasLogin(state){
      state.hasLogin=false
    }
  },
  actions: {
    async getUser({ commit,state }) {
      const {
        data
      } = await getUserInfoApi();
      // console.log(data);
      commit('getInfo', data)
      state.hasLogin=true
    },
  },
}